package com.wgs.onomastici;

import java.io.IOException;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

public class CercaPerData extends AbstractBaseActivity implements OnClickListener{

	private DatePicker data;
	private Button cerca;
	private TextView santi;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_cerca_per__data);
		Resources res = getResources();
		setInfoMessage(res.getString(R.string.info_msg_cercaperdata));
		/************* Attivazione listener, pulsanti e DataPicker *************/
		cerca = (Button)findViewById(R.id.inizia_ricerca_data);
		cerca.setOnClickListener(this);
		data = (DatePicker)findViewById(R.id.prendi_data);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_cerca_per__data, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		
		
		AssetManager manager = getAssets();
		XmlParser parser;
		try {
			parser = XmlParser.getInstance(manager);
			
			Finder finder = new Finder(parser.getDocument());
			
			int day = data.getDayOfMonth();
			int month = data.getMonth()+1;
			
			/************* Ricerca Santi in base alla data selezionata e stampa risultati *************/
			List<String> lista_santi = finder.findByDate(String.valueOf(day),String.valueOf(month));
			santi = (TextView)findViewById(R.id.santi_trovati);
			santi.setGravity(Gravity.TOP);
			santi.setTextSize(18);
			santi.setTypeface(null,1);
			santi.setText(finder.formatSanti(lista_santi));
			
			
		
		} catch (IOException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		}
		
		
	}
	
	
	
}
